<template>
  <el-dialog :title="info.title" :visible.sync="visible" center width="1460px" :before-close="handleCancel">
    <div class="">
      <el-table
          ref="multipleTable"
          class="search-table"
          :data="list"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="序号" align="center" width="56px">
            <template slot-scope="{$index}">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="供应商名称" min-width="220px">
            <template slot-scope="{row}">
              {{ row.sup_name ? row.sup_name : '仓库' }}
            </template>
          </el-table-column>
          <el-table-column label="项目名称" min-width="220px" prop="pro_name" />
          <el-table-column label="PO单号" width="190px">
            <template slot-scope="{row}">
              {{ 'PO'+row.pro_id }}
            </template>
          </el-table-column>
          <el-table-column label="签订公司" width="220px" :formatter="formatterCompany" />
          <el-table-column label="采购日期" align="center" width="140px" prop="pur_time" />
          <el-table-column label="采购金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="追加金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.additional, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="追减金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.reduction, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="已付款金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.pay, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="未付款金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price + row.additional - row.reduction - row.pay, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="已开票金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.has_tax, 2) }}
            </template>
          </el-table-column>
          <el-table-column label="未开票金额" align="right" width="140px">
            <template slot-scope="{row}">
              {{ app.toFix(row.price + row.additional - row.reduction - row.has_tax, 2)  }}
            </template>
          </el-table-column>
          <el-table-column label="采购类型" align="center" width="90px" :formatter="formatterType" />
          <el-table-column label="备注" min-width="220px" prop="remark" />
        </el-table>
        <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    </div>
  </el-dialog>
</template>

<script>
import page from '@/utils/page'
import { payableInfos } from '@/api/statistics/statistics'

export default {
  components: { },
  extends: page,
  inject: ['app'],
  props: {
    info: {
      type: Object,
      default: null
    },
    reqList: {
      default: payableInfos,
      type: Function
    }
  },
  data() {
    return {
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.$set(this, 'form', this.info.edit)
        this.$set(this.filter, 'sup_id', this.form.sup_id)
        this.getList()
        this.$nextTick(() => {
          this.$refs.multipleTable.doLayout()
        })
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    formatterType(row) {
      let type = ''
      if (row.type === 1) {
        type = '物料采购'
      } else if (row.type === 2) {
        type = '设备采购'
      } else if (row.type === 3) {
        type = '工程外包'
      } else if (row.type === 4) {
        type = '库存出库'
      }
      return type
    },
    formatterCompany(row) {
      let company = ''
      if (row.company && row.company !== '') {
        company = row.company
      } else if (row.entrust_name && row.entrust_name !== '') {
        company = row.entrust_name
      } else if (row.type === 4) {
        company = '里欧总公司'
      }
      return company
    }
  }
}
</script>

<style scoped>
</style>
